/*
 * @Author: ૮₍ ˙О˙₎ა
 * @Date: 2023-07-22 09:09:41
 */
/*
 * @Author: ૮₍ ˙О˙₎ა
 * @Date: 2023-07-22 09:09:41
 */
import { http } from '@/utils/request'
import type { IEditRoleData, IRoleListData, IUpdateRoleParams } from '@/types/role'
import _ from 'lodash'

/**
 * 获取角色列表
 * @param page 当前页码
 * @param limit 每页请求条数
 * @param roleName 角色名字
 * @returns
 */
export const reqRoleList = (page: number, limit: number, roleName?: string) => {
  // return request.request<ResponseData<IRoleListData>>({
  //   method: 'GET',
  //   url: `/admin/acl/role/${page}/${limit}`,
  //   params: { roleName }
  // })
  return http<IRoleListData>(`/admin/acl/role/${page}/${limit}`, 'GET', _.pickBy({ roleName }))
}

/**
 * @description 新增角色
 * @param params 新增的角色名称
 * @returns
 */
export const reqSaveRole = (params: { roleName: string }) => {
  return http(`admin/acl/role/save`, 'POST', params)
}

/**
 * @description 删除角色
 * @param id 角色 Id
 * @returns
 */
export const reqDelRole = (id: number) => {
  return http(`admin/acl/role/remove/${id}`, 'DELETE')
}

/**
 * @description 更新用户信息
 * @param params
 * @returns
 */
export const reqUpdateRole = (params: IUpdateRoleParams) => {
  return http('/admin/acl/role/update', 'PUT', params)
}

/**
 * @description 获取编辑角色列表页的列表
 * @param id
 * @returns
 */
export const reqEditRoleList = (id: string) => {
  return http<IEditRoleData>(`/admin/acl/permission/toAssign/${id}`, 'GET')
}

/**
 * @description 编辑角色
 * @param params
 * @returns
 */
export const reqSetRole = (roleId: string, permissionId: string) => {
  return http(
    `/admin/acl/permission/doAssign?roleId=${roleId}&permissionId=${permissionId}`,
    'POST'
  )
}
